import { NTab, type TabProps } from "naive-ui";
import type { HTMLAttributes } from "vue";
import { getSlotsDom } from "../utils";
import type { BaseComponentType } from "../types";
export type OmitTabProps<K extends keyof TabProps> = Omit<TabProps, K>;
export type TabFactoryConstructorType = {
    attrs?: HTMLAttributes;
    props?: OmitTabProps<"name"> & { name: string | number };
    defaultSlot?: BaseComponentType
}
export class TabFactory {
  private attrs: HTMLAttributes = {};
  private props: OmitTabProps<"name"> & { name: string | number } = {
    name: "",
  };
  private defaultSlot: BaseComponentType = null;

  constructor(data?: TabFactoryConstructorType) {
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.props) this.setProps(data.props);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
  }

  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this
  }
  setProps(props: OmitTabProps<"name"> & { name: string | number }) {
    this.props = props;
    return this
  }
  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this
  }

  create() {
    return (
      <NTab {...this.attrs} {...this.props}>
        {{
          default:
            this.defaultSlot != null
              ? () => getSlotsDom(this.defaultSlot)
              : null,
        }}
      </NTab>
    );
  }
}
